<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/uilibs.jsp"%>
</head>
<body>
<div id="layout" class="mini-layout" style="width:100%;height:100%;"  borderStyle="border:solid 0px #aaa;">
    <div title="center" region="center">
        <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="add">增加</a> 
                        <a class="mini-button" iconCls="icon-edit" onclick="edit">编辑</a> 
                        <a class="mini-button" iconCls="icon-remove" onclick="remove">删除</a>
                        <span class="separator"></span>
                        <input class="mini-textbox" id="key" emptyText="字典名称" onenter="query()">
                        <a class="mini-button" iconCls="icon-find" onclick="query()">查询</a>
                    </td>
                </tr>
            </table>
        </div>
        <div class="mini-fit">
            <div id="grid" class="mini-datagrid" style="width:100%;height:100%;"
                url="${ctx}/system/common/grid" idField="name" multiSelect="true"
                showEmptyText="true" emptyText="暂无记录" sizeList="[5,10,20,50]" pageSize="20">
                <div property="columns">
                    <div type="checkcolumn" width="5"></div>
                    <div field="name" width="20" headerAlign="center" allowSort="true">字典名称</div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
var grid = null;

$(function(){
    mini.parse();
    grid = mini.get("grid");
    var params={};
    params.sql="select distinct name from system_dict";
    grid.load(params);
});

function query(){
    var v = mini.get("key").getValue();
    var params={};
    params.sql="select distinct name from system_dict where name like '%"+v+"%'";
    grid.load(params);
}

function add(){
    mini.open({
        url : "${ctx}/system/dict/edit",
        title : "新增",
        width : 550,
        height : 400,
        onload : function() {
            var iframe = this.getIFrameEl();
            var data = {
                action : "new"
            };
        },
        ondestroy : function(action) {
            grid.reload();
        }
    });
}

function edit() {
    var row = grid.getSelected();
    if (row && row.name) {
        mini.open({
            url : "${ctx}/system/dict/edit?name="+encodeURI(encodeURI(row.name)),
            title : "编辑",
            width : 550,
            height : 400,
            onload : function() {
                var iframe = this.getIFrameEl();
                var data = {
                    action : "edit",
                    id : row.id
                };
            },
            ondestroy : function(action) {
                grid.reload();
            }
        });
    } else {
        mini.alert("请选中一条记录!");
    }
}

function remove() {
    var names = "";
    var rows = grid.getSelecteds();
    if(rows && rows.length > 0){
        var arr = [];
        for(var i = 0, l = rows.length; i < l; i++){
            if(!rows[i].name)continue;
            arr.push("'"+rows[i].name+"'");
        }
        names = arr.join(',');
    }
    if (names && names.length>0) {
        if (confirm("确定删除选中记录？")) {
            grid.loading("操作中，请稍后......");
            Dao.update("delete from system_dict where name in("+names+")",function(data){
                if(data){
                    grid.reload();
                } else {
                    mini.alert("服务器异常，请稍后重试!");
                }
            });
        }
    } else {
        mini.alert("请选中一条记录");
    }
}

</script>
</body>
</html>